﻿#region Copyright
/* © 2008 George Tsiokos, licensed under the Microsoft Reciprocal License (Ms-RL) */
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Comet.Diagnostics.PerformanceCounters;

namespace Comet.Diagnostics {
    internal static class PerformanceCounterUtility {

		#region Fields (3) 

        private const string __category = "Comet";
        private const string __categoryDescription = "Consists of counters that monitor Comet connections and applications.";
        private static readonly Dictionary<Type, CounterCreationData> __counters = new Dictionary<Type, CounterCreationData> () {
            { typeof(ConnectionWaitTime), new ConnectionWaitTime () }
        };

		#endregion Fields 

		#region Properties (1) 

        public static string Category {
            get {
                return __category;
            }
        }

		#endregion Properties 

		#region Methods (3) 


		// Public Methods (3) 

        public static PerformanceCounter GetInstance<T> (string instanceName) {
            return new PerformanceCounter (__category, __counters[typeof (T)].CounterName, instanceName, false);
        }

        public static void Install () {
            PerformanceCounterCategory.Create (
                __category,
                __categoryDescription,
                PerformanceCounterCategoryType.MultiInstance,
                new CounterCreationDataCollection (__counters.Values.ToArray ()));
        }

        public static void Uninstall () {
            PerformanceCounterCategory.Delete (__category);
        }


		#endregion Methods 

    }
}